/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.srcptit.trainning.b1;

import static com.srcptit.trainning.b1.B6_soThuanNghich.soTN;

/**
 *
 * @author Administrator
 */
public class B7_nguyenToThuanNghichFibo {
    public static void main(String[] args) {
        lietKe(7);
    }
    static boolean soTN(long n){
        long k = 0, kq = n;
        while(kq>0){
            k = 10*k + kq%10;
            kq /= 10;
        }
        return (n==k);
    }
    static boolean isPrime(long n){
        if(n<2) return false;
        if(n==2) return true;
        if(n%2==0) return false;
        for(long i=3;i<=(long)Math.sqrt(n);i+=2)
            if(n%i==0) return false;
        return true;
    }
    static int tongChuSo(long n){
        int s = 0;
        while(n>0){
            s+=n%10;
            n /= 10;
        }
        return s;
    }
    static boolean isFibo(long n){
        long i = 0, j = 1, t, d = 2, kq = tongChuSo(n);
        while(j<kq){
            t = i + j;
            i = j;
            j = t;
        }
        return (j==kq);
    }
    static void lietKe(int n){
        long n1 = (long)Math.pow(10,n-1);
        long n2 = (long)Math.pow(10, n);
        for(long i=n1;i<n2;i++)
            System.out.print((soTN(i) && isPrime(i) && isFibo(i))?("\n"+i):(""));
    }
}
